package com.example.demo.controller;

import com.example.demo.entity.Role;
import com.example.demo.service.RoleService;
import com.example.demo.service.UserRoleService;
import com.example.demo.vo.RoleMenuRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @author moguai
 * @version 1.0
 * @date 2022/3/18 13:09
 */
@RestController
@RequestMapping("/api")
@Api(tags = "角色操作")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @Autowired
    @Qualifier(value = "userRoleServiceImpl")
    private UserRoleService user_roleService;

    @ApiOperation("查找")
    @RequestMapping(value = "/role", method = RequestMethod.GET)
    public Role selectRole(Integer id) {
        return roleService.selectRole(id);
    }

    @ApiOperation("插入")
    @RequestMapping(value = "/role", method = RequestMethod.POST)
    public void insertRole(RoleMenuRequest request) {
        roleService.insertRole(request);
    }

    @ApiOperation("更新")
    @RequestMapping(value = "/role", method = RequestMethod.PUT)
    public void updateRole(RoleMenuRequest request) {
        roleService.updateRole(request);
    }

    @ApiOperation("删除")
    @RequestMapping(value = "/role", method = RequestMethod.DELETE)
    public void deleteRole(Integer id) {
        List<Integer> ids = Collections.singletonList(id);
        roleService.deleteRole(ids);

    }
}
